package com.sifang.bussiness.merchant.contorller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sifang.bussiness.base.BaseController;
import com.sifang.bussiness.merchant.bean.MerchantReqCheckPay;
import com.sifang.bussiness.merchant.bean.MerchantRspCheckPay;
import com.sifang.bussiness.merchant.bean.MerchantRspErrorResult;
import com.sifang.bussiness.merchant.service.MerchantCheckPayService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class MerchantCheckPayController extends BaseController {
	
	
	private static Logger log = LoggerFactory.getLogger(MerchantCheckPayController.class);
	
	@Autowired
	MerchantCheckPayService merchantCheckPayService;
			
	@RequestMapping(value = "/pay/payCheck")
	public void checkPay(HttpServletRequest request,HttpServletResponse response) {
		response.setHeader("Content-Type", "text/json;charset=UTF-8");
		try {
			MerchantReqCheckPay merchantReqCheckPay = (MerchantReqCheckPay)request.getAttribute("msg");
			MerchantRspCheckPay MerchantRspCheckPay = merchantCheckPayService.checkPay(merchantReqCheckPay);

			if(MerchantRspCheckPay.getCode().equals("success")) {
				writeToJson(response,MerchantRspCheckPay);
			}else {
				MerchantRspErrorResult merchantRspErrorResult = new MerchantRspErrorResult();
				merchantRspErrorResult.setCode("error");
				merchantRspErrorResult.setMsg(MerchantRspCheckPay.getMsg());
				writeToJson(response,merchantRspErrorResult);
			}
		}catch (Exception e) {
			log.error("查询支付异常",e);
			MerchantRspErrorResult merchantRspErrorResult = new MerchantRspErrorResult();
			merchantRspErrorResult.setCode("error");
			merchantRspErrorResult.setMsg("查询支付异常");
			writeToJson(response,merchantRspErrorResult);
		}
	}
}
